package com.xixi.demo.mapper;

import com.xixi.demo.model.UserInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface UserMapper {
    @Select("select user_name, github_url, head_portrait from user where id = #{id} and delete_flag = 0")
    UserInfo selectById(Integer id);

    @Select("select id, user_name, password, github_url from user where user_name = #{userName} and delete_flag = 0")
    UserInfo selectByName(String userName);

    @Insert("insert into user (user_name, password, github_url) values (#{userName}, #{password}, #{githubUrl})")
    Integer insertUser(String userName, String password, String githubUrl);

    Integer updateUser(UserInfo userInfo);

    @Update("update user set delete_flag = 1 where id = #{id}")
    Integer deleteUser(Integer id);

    @Select("select count(1) from blog where user_id = #{userId}")
    Integer selectCount(Integer userId);
}
